Ext.define('Holo.controller.WindowsNewTrip', {
    extend: 'Ext.app.Controller',
	
    views: [
        'trip.WindowsNewTrip'
    ],
    
    stores: [
        'Trips',
    ],
    
    
    refs: [
            {
                selector: '#WindowsNewTripForm',
                ref: 'formNewTrip'
            },{
                selector: 'windowsnewtrip',
                ref: 'WindowsNewTrip'
            }
    ],



    /**
     * docs
     */
    init: function() {
    	 this.control({
	    'windowsnewtrip' :{
		    afterlayout : function (form){
                        GlobalData.currentController = this;
                    } 
            },
	    
            'windowsnewtrip button[action=createtrip]': {
                click : this.createNewTrip
            }  
        
        });
    },
    

    /**
     * docs
     */
    createNewTrip : function(){
        var data = this.getFormNewTrip().getValues();
        try{
            var newTrip = Ext.create('Holo.model.Trip', {
                            name: data.name,
                            type: 'A',
                            duration : 60,
                            status: 'B',
                            user_id : GlobalData.currentUserId
                        });
            
            this.getTripsStore().add(newTrip);             
        }catch(err){
                console.log('erreur : controller/WindowsNewTrip.createNewTrip() =>'+ err.message);
        }
    },
    
    
    /**
     * docs
     */
    screenUpdate : function(){
      
        var controllerMenu = this.getController('MainMenu');
        controllerMenu.setItemsToSelectTripMenu();
        controllerMenu.showTripManager();
        
        this.getWindowsNewTrip().close();   
        
    }
    
 });